package com.haidechizi.longpolling.event.listener;

import com.haidechizi.longpolling.event.Event;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author wangdejun
 * @create 2021/2/24 13:39
 */
@Slf4j
public abstract class AbstractEventListener implements EventListener {

    @PostConstruct
    public void init() {
        List<Class<? extends Event>> interests = interests();
        if (CollectionUtils.isEmpty(interests)) {
            log.error("没有感兴趣的事件");
            return;
        }
        interests.forEach(clazz -> EventDispatcher.addListener(clazz, this));
    }


}
